package com.sunnada.edu.system.sysmodule.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sunnada.edu.system.sysmodule.dao.ModuleDao;
import com.sunnada.edu.system.sysrole.service.RoleMethods;
import com.sunnada.edu.system.pub.common.Common;



@Service
@Transactional
public class ModuleServiceImpl implements ModuleService {
	@Resource
	ModuleDao moduleDao;
	@Override
	public int getModuleCots(HashMap<String, String> params) {
		return moduleDao.getModuleCots(params);
	}
	@Override
	public List<?> findModules(HashMap<String, String> params) {
		return moduleDao.findModules(params);
	}

	@Override
	public String moduleDel(HashMap<String, String> params) {
		String msg = null;
		List leaflList = moduleDao.judgeHasLeaf(params);
		if(leaflList.size() > 0){
			msg = "你要删除的模块存在子模块，不允许删除！";
		}else{
			int num = moduleDao.moduleDel(params);
			if(num==0){
				msg = "删除失败!";
			}
		}
		
		return msg;
	}

	@Override
	public String moduleAdd(HashMap<String, String> params) {
		String msg = "";
		String recId=UUID.randomUUID().toString();
		params.put("recId", recId);
		params.put("moduleId", recId);
		int num = moduleDao.moduleAdd(params);
		//给admin 的超级管理员角色rec_id='1' 添加这个菜单
		RoleMethods.insertModuleToRole(params);
		if(num==0){
			msg = "添加失败!";
		}
		return msg;
	}

	@Override
	public String moduleUpdate(HashMap<String, String> params) {
		String msg = "";
		int num = moduleDao.moduleUpdate(params);
		if(num==0){
			msg = "修改失败!";
		}
		return msg;
		
	}

	@Override
	public Map getModuleByRecId(HashMap<String, String> params) {
		return moduleDao.getModuleByRecId(params);
	}
	@Override
	public List moduleTree(HashMap<String, String> params) {
		return moduleDao.moduleTree(params);
	}
	@Override
	public List moduleTree2(HashMap<String, String> params) {
		return moduleDao.moduleTree2(params);
	}
	@Override
	public List moduleTree3(HashMap<String, String> params) {
		return moduleDao.moduleTree3(params);
	}
	@Override
	public String moduleEnable(HashMap<String, String> params) {
		String msg=null;
		int num=moduleDao.moduleEnable(params);
		if (num==0) {
			msg="模块启用失败！";
		}
		return msg;
	}
	@Override
	public String moduleDisable(HashMap<String, String> params) {
	    String msg=null;
	    int num= moduleDao.moduleDisable(params);
	    if (num==0) {
			msg="模块停用失败！";
		}
	    return msg;
	}
	
}
